package com.yanqu.road.server.cmd.palace;

import com.yanqu.road.entity.decoration.DecorationSimple;
import com.yanqu.road.logic.pb.DecorationPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.decoration.DecorationProto;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.palace.CrossPalaceActivity;
import com.yanqu.road.server.manager.palace.CrossPalaceActivityMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.C_PALACE_PLAYER_DECORATION_SYNC, desc = "玩家称号同步")
public class CrossPalaceDecorationSyncCmd extends CrossCommand {
    private int activityId;
    private long userId;
    private List<DecorationSimple> decorationSimpleList = new ArrayList<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        EstateWarProto.PalaceDecorationSimpleSyncMsg reqMsg = EstateWarProto.PalaceDecorationSimpleSyncMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        userId = reqMsg.getUserId();
        if(reqMsg.getDataListCount() > 0){
            for(DecorationProto.DecorationSimpleTempMsg tempMsg : reqMsg.getDataListList()){
                DecorationSimple data = DecorationPb.parseDecorationSimple(tempMsg);
                if(null != data) {
                    decorationSimpleList.add(data);
                }
            }
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossPalaceActivity crossPalaceActivity = CrossPalaceActivityMgr.getCrossPalaceActivity(activityId);
        if(null != crossPalaceActivity){
            crossPalaceActivity.syncDecorationSimple(userId, decorationSimpleList);
        }
    }

    @Override
    public void sendData() {

    }
}
